package com.example.lilei.Loves;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;

import com.example.lilei.R;
import com.example.lilei.Views.ExplosionField;

public class Love_1Activity extends AppCompatActivity {
    private ExplosionField mExplosionField;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.activity_love_1);
        mExplosionField = ExplosionField.attach2Window(this);
        addListener(findViewById(R.id.root));

    }
    private void addListener(View root){
        if(root instanceof ViewGroup){
            ViewGroup parent = (ViewGroup) root;
            for(int i = 0;i<parent.getChildCount();i++){
                addListener(parent.getChildAt(i));
            }
        }else {
            root.setClickable(true);
            root.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mExplosionField.explode(v);
                    v.setOnClickListener(null);
                    Intent intent = new Intent(Love_1Activity.this,Love_2Activity.class);
                    startActivity(intent);
                }
            });
        }
    }

//    private void reset(View root){
//        if(root instanceof ViewGroup){
//            ViewGroup parent = (ViewGroup) root;
//            for(int i = 0;i<parent.getChildCount();i++){
//                reset(parent.getChildAt(i));
//            }
//        }else {
//            root.setScaleX(1);
//            root.setScaleY(1);
//            root.setAlpha(1);
//        }
//    }
}
